<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@page import="com.zaofan.bean.Admin" %>
<%@page import="com.zaofan.bean.AdminType" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
 String contextPath = request.getContextPath();
 Admin admin = (Admin) session.getAttribute("admin");
 if (admin == null) {
  response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
  return;
 }
 if (admin.getType() != AdminType.admin.ordinal() && admin.getType() != 4) {
  response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
  return;
 }
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <title>总新用户</title>
 <link href="<%=contextPath%>/admin/css/base.css" rel="stylesheet"/>
 <link href="<%=contextPath%>/admin/assets/css/bootstrap.min.css" rel="stylesheet"/>
 <link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome.min.css"/>
 <!--[if IE 7]>
 <link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome-ie7.min.css"/>
 <![endif]-->
 <link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace.min.css"/>
 <link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-rtl.min.css"/>
 <link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-skins.min.css"/>
 <!--[if lte IE 8]>
 <link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-ie.min.css"/>
 <![endif]-->
 <script src="<%=contextPath%>/admin/assets/js/ace-extra.min.js"></script>
 <!--[if lt IE 9]>
 <script src="<%=contextPath%>/admin/assets/js/html5shiv.js"></script>
 <script src="<%=contextPath%>/admin/assets/js/respond.min.js"></script>
 <![endif]-->
 <link rel="stylesheet"
       href="<%=contextPath%>/admin/assets/css/jquery-ui-1.10.3.custom.min.css"/>
 <link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/chosen.css"/>
 <link rel="stylesheet"
       href="<%=contextPath%>/admin/assets/css/daterangepicker.css"/>
 <script type="text/javascript">
  var contextPath = '<%=contextPath%>';
 </script>
</head>
<body style="background-color: #fff;">
<div class="breadcrumbs" id="breadcrumbs">
 <script type="text/javascript">
  try {
   ace.settings.check('breadcrumbs', 'fixed')
  } catch (e) {
  }
 </script>
 <ul class="breadcrumb" style="padding: 20px; color: #3a87ad;">
 </ul>
</div>




<div class="page-content">
 <div class="row" style="height: 100%">


  <div class="col-xs-12">
   <div class="panel panel-default">
    <div class="panel-heading">订单查找</div>
    <div class="panel-body">
     <form class="form-inline">

      <input type="hidden" value="" id="orderTime"  />
      <input type="hidden" value="" id="key"/>
      <label for="key">推广人员姓名：</label>
      <input id="membername" class="form-control" value="" style="width:150px;"/>&nbsp;&nbsp;
      <br/><br/>

      <label for="key">注册时间:</label>
      <input  class="form-control" value="" style="width:200px;" type="text"
              name="date-range-picker" id="id-date-range-picker-1"/>
      <select id="citys" style="width:150px;">
       <option value="-1">全部</option>
      </select>&nbsp;&nbsp;
      <label for="key">区域:</label>
      <select id="areas" style="width:150px;" >

      </select>&nbsp;&nbsp;
      <label for="key">大楼:</label>
      <select id="builders" style="width:150px;" >

      </select>&nbsp;&nbsp;<br/><br/>
      <button type="button" class="btn btn-primary btn-sm" id="findByTime">查找
      </button>
      <button type="button" class="btn btn-primary btn-sm" id="print">打印</button>
     </form>
    </div>
   </div>
  </div>


  <div class="col-xs-12">
   <style>
    .table-responsive table th tr {
     text-align: center;
    }
   </style>
   <div class="table-responsive">

    <input type="hidden" value="1" id="start"/>

    <table id="sample-table-2"
           class="table table-striped table-bordered table-hover">
     <thead>
     <tr>
      <th style="text-align: center;">手机号</th>
      <th style="text-align: center;">注册时间</th>

     </tr>
     </thead>
     <tbody id="data-list" style="text-align: center;">
     </tbody>
    </table>
   </div>
  </div>
  <!-- /.col -->


 </div>
 <!-- /.row -->
 <div class="row">
  <div class="col-sm-6">
   <div id="sample-table-2_info" class="dataTables_info">
    总共 <span
           id="total"></span> 条
   </div>
  </div>
 </div>

</div>
<div id="loading"
     style="width: 32px; height: 32px; position: fixed; left: 40%; top: 40%; display: none;">
 <img src="<%=contextPath%>/admin/assets/css/images/loading.gif"
      width="32" height="32"/>
</div>
<div class="popover"
     style="z-index: 9999; width: 150px; position: fixed; left: 40%; top: 40%;">
 <div class="arrow"></div>
 <div class="popover-inner">
  <h3 class="popover-title">操作提示</h3>
  <div class="popover-content" id="popover-content">
   <p>操作成功</p>
  </div>
 </div>
</div>

<script type="text/javascript">
 if ("ontouchend" in document)
  document
          .write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
</script>
<script type="text/javascript">
 window.jQuery
 || document
         .write("<script src='<%=contextPath%>/admin/assets/js/jquery-2.0.3.min.js'>"
                 + "<" + "script>");
</script>

<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='<%=contextPath%>/admin/assets/js/jquery-1.10.2.min.js'>" + "<" + "script>");
</script>
<![endif]-->
<script type="text/javascript">
 if ("ontouchend" in document)
  document
          .write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
                  + "<" + "script>");
</script>


<script src="<%=contextPath%>/admin/assets/js/bootstrap.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/typeahead-bs2.min.js"></script>

<!--[if lte IE 8]>
<script src="assets/js/excanvas.min.js"></script>
<![endif]-->
<script src="<%=contextPath%>/admin/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/jquery.ui.touch-punch.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/jquery.slimscroll.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/jquery.easy-pie-chart.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/jquery.sparkline.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/ace-elements.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/ace.min.js"></script>
<script src="<%=contextPath%>/admin/js/common.js"></script>
<script src="<%=contextPath%>/admin/assets/js/jquery-form.js"></script>
<script src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
<script src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
<script src="<%=contextPath%>/admin/assets/js/date-time/bootstrap-datepicker.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/date-time/moment.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/date-time/daterangepicker.min.js"></script>



<script type="text/javascript">
 $('input[name=date-range-picker]').daterangepicker().prev().on(ace.click_event, function () {
  $(this).next().focus();
 });

 getData();

 function getData(name,ordertime,builderid) {

  $("#loading").show();
  $.ajax({
   url: contextPath + '/m/QRCode/NewUser',
   type: "GET",
   dataType: 'json',
   data:{
    qr_code_desc:name,
    orderTime:ordertime,
    builderId:builderid
   },
   success: function (rs) {
    console.log(rs);
    if (rs.success) {
     var data = rs.data;
     $("#total").text(rs.total);
     var dataList = $("#data-list");
     dataList.empty();

     if (data.length > 0) {
      parseData(data);

      $("#print").on('click',function () {

       exportdata(name,ordertime,builderid);
      })

     } else {
      $("#print").off('click');
      showMessage("无数据");
      $("#total").text(0);
      $("#data-list").html("");
     }
    } else {
     $("#print").off('click');
     showMessage(rs.msg);
     $("#total").text(0);
     $("#data-list").html("");
    }
    $("#loading").hide();

   },
   error: function () {
    $("#loading").hide();
    showMessage("请稍后再试");
   }
  });
 }


 function exportdata(qr_code_desc,orderTime,builderid) {
  window.location.href =  contextPath + '/order?action=exportNewUser&qr_code_desc='+qr_code_desc+'&orderTime='+orderTime+'&builderId='+builderid;
 }




 function parseData(data) {
  var tr = "";
  for (var i = 0; i < data.length; i++) {
   tr += '<tr>';
   tr += '<td>' + data[i].mobile + '</td>';
   tr += '<td>' + data[i].regeistDate + '</td >';
   tr += '</tr>';
  }

  $("#data-list").append(tr);



 }




 $("#findByTime").click(function () {
  var time = $("#id-date-range-picker-1").val();

  if(time == "" || time == null){
   time="";
  }else{
   time = time.replace(" - ", ",");
  }


  $("#orderTime").val(time);

  var name  = encodeURI($("#membername").val());

  var builderid  =  $("#builders").val();

  getData(name,time,builderid);


 });




 $.ajax({
  url : contextPath + '/city',
  type : "POST",
  dataType : 'json',
  data : {
   action : 'list',
   order:' by sort asc'
  },
  success : function(rs, textStatus, jqXHR) {
   if (rs.success) {
    var data = rs.data;
    var options = "";
    for(var i = 0 ; i < data.length ; i++){
     options += '<option value="'+data[i].id+ '">' + data[i].cityName + '</option>';
    }
    $("#citys").append(options);
    $("#citys").val(1);
    $.ajax({
     url : contextPath + '/area',
     type : "POST",
     dataType : 'json',
     data : {
      action : 'list',
      cityId:1,
      order:' by sort asc'
     },
     success : function(rs, textStatus, jqXHR) {
      if (rs.success) {
       var data = rs.data;
       var options = '<option value="-1" selected="selected">全部</option>';
       for(var i = 0 ; i < data.length ; i++){
        options += '<option value="'+data[i].id+ '">' + data[i].areaName + '</option>';
       }
       $("#areas").empty();
       $("#areas").append(options);
      } else {
       showMessage("获取数据失败,请稍后再试");
      }
      $("#loading").hide();
     },
     error : function() {
      $("#loading").hide();
      showMessage("请稍后再试");
     }
    });
   } else {
    showMessage("获取数据失败,请稍后再试");
   }
   $("#loading").hide();

  },
  error : function() {
   $("#loading").hide();
   showMessage("请稍后再试");
  }
 });


 $("#citys").change(function(){
  var val = $(this).val();
  if(val != -1){
   $.ajax({
    url : contextPath + '/area',
    type : "POST",
    dataType : 'json',
    data : {
     action : 'list',
     cityId:val,
     order:' by sort asc'
    },
    success : function(rs, textStatus, jqXHR) {
     if (rs.success) {
      var data = rs.data;
      var options = '<option value="-1">全部</option>';
      for(var i = 0 ; i < data.length ; i++){
       options += '<option value="'+data[i].id+ '">' + data[i].areaName + '</option>';
      }
      $("#areas").empty();
      $("#areas").append(options);
     } else {
      showMessage("获取数据失败,请稍后再试");
     }
     $("#loading").hide();
    },
    error : function() {
     $("#loading").hide();
     showMessage("请稍后再试");
    }
   });
  }
 });

 $("#areas").change(function(){
  var val = $(this).val();
  $("#areaId").val(val);
  if(val != -1){
   $.ajax({
    url : contextPath + '/builder',
    type : "POST",
    dataType : 'json',
    data : {
     action : 'list',
     areaId:val,
     cityId:$("#citys").val(),
     order:' by sort asc'
    },
    success : function(rs, textStatus, jqXHR) {
     if (rs.success) {
      var data = rs.data;
      var options = '<option value="-1">全部</option>';
      for(var i = 0 ; i < data.length ; i++){
       options += '<option value="'+data[i].id+ '">' + data[i].builderName + '</option>';
      }
      $("#builders").empty();
      $("#builders").append(options);
     } else {
      showMessage("获取数据失败,请稍后再试");
     }
     $("#loading").hide();

    },
    error : function() {
     $("#loading").hide();
     showMessage("请稍后再试");
    }
   });
  }

 });








</script>
</body>

</html>